var refundCensus =null;
var courseCensus = null;
var goodsCensus = null;
var refundCensusSum = 0;
var courseCensusSum =0;
var goodsCensusSum = 0;
$.ajax({
    type:"get",
    url:"/order/census",
    data:{},
    async:false,
    success:function (res){
        refundCensus =res.refundCensus;
        courseCensus = res.courseCensus;
        goodsCensus = res.goodsCensus;
        for (let i = 0; i < refundCensus.length; i++) {
            refundCensusSum = refundCensusSum +refundCensus[i].orderId;
        }
        for (let i = 0; i < courseCensus.length; i++) {
            courseCensusSum = courseCensusSum +courseCensus[i].orderId;
        }
        for (let i = 0; i < goodsCensus.length; i++) {
            goodsCensusSum = goodsCensusSum +goodsCensus[i].orderId;
        }

    }
})
// 基于准备好的dom，初始化echarts实例
var dom = document.getElementById('main0');
var myChart = echarts.init(dom);

// 指定图表的配置项和数据
var option = {
    title: {
        text: '课程上架数量'
    },
    tooltip: {},
    legend: {
        data: ['商品订单', '课程订单', '退货订单']
    },
    xAxis: {
        data: [refundCensus[0].orderSubmissionTime,
            refundCensus[1].orderSubmissionTime,
            refundCensus[2].orderSubmissionTime,
            refundCensus[3].orderSubmissionTime,
            refundCensus[4].orderSubmissionTime,
            refundCensus[5].orderSubmissionTime,
            refundCensus[6].orderSubmissionTime]
    },
    yAxis: {},
    series: [
        {
            name: '退货订单',
            type: 'bar',
            data: [
                refundCensus[0].orderId,
                refundCensus[1].orderId,
                refundCensus[2].orderId,
                refundCensus[3].orderId,
                refundCensus[4].orderId,
                refundCensus[5].orderId,
                refundCensus[6].orderId]
        },
        {
            name: '课程订单',
            type: 'bar',
            data: [
                courseCensus[0].orderId,
                courseCensus[1].orderId,
                courseCensus[2].orderId,
                courseCensus[3].orderId,
                courseCensus[4].orderId,
                courseCensus[5].orderId,
                courseCensus[6].orderId]
        },
        {
            name: '商品订单',
            type: 'bar',
            data: [
                goodsCensus[0].orderId,
                goodsCensus[1].orderId,
                goodsCensus[2].orderId,
                goodsCensus[3].orderId,
                goodsCensus[4].orderId,
                goodsCensus[5].orderId,
                goodsCensus[6].orderId]
        }
    ]
};
var option1 = {
    title: {
        text: '课程上架数量'
    },
    tooltip: {},
    legend: {
        data: ['商品订单', '课程订单', '退货订单']
    },
    xAxis: {
        data: [refundCensus[0].orderSubmissionTime,
            refundCensus[1].orderSubmissionTime,
            refundCensus[2].orderSubmissionTime,
            refundCensus[3].orderSubmissionTime,
            refundCensus[4].orderSubmissionTime,
            refundCensus[5].orderSubmissionTime,
            refundCensus[6].orderSubmissionTime]
    },
    yAxis: {},
    series: [
        {
            name: '退货订单',
            type: 'line',
            data: [
                refundCensus[0].orderId,
                refundCensus[1].orderId,
                refundCensus[2].orderId,
                refundCensus[3].orderId,
                refundCensus[4].orderId,
                refundCensus[5].orderId,
                refundCensus[6].orderId]
        },
        {
            name: '课程订单',
            type: 'line',
            data: [
                courseCensus[0].orderId,
                courseCensus[1].orderId,
                courseCensus[2].orderId,
                courseCensus[3].orderId,
                courseCensus[4].orderId,
                courseCensus[5].orderId,
                courseCensus[6].orderId]
        },
        {
            name: '商品订单',
            type: 'line',
            data: [
                goodsCensus[0].orderId,
                goodsCensus[1].orderId,
                goodsCensus[2].orderId,
                goodsCensus[3].orderId,
                goodsCensus[4].orderId,
                goodsCensus[5].orderId,
                goodsCensus[6].orderId]
        }
    ]
};
var option2 = {
    title: {
        text: '课程上架数量'
    },
    tooltip: {},
    legend: {
        data: ['商品订单', '课程订单', '退货订单']
    },
    series: [
        {
            type: 'pie',
            data: [
                {
                    value: refundCensusSum,
                    name: "退货订单"
                },
                {
                    value: courseCensusSum,
                    name: "课程订单"
                },
                {
                    value: goodsCensusSum,
                    name: "商品订单"
                }
            ]
        }
    ]
};

// 使用刚指定的配置项和数据显示图表。
option && myChart.setOption(option);
function zx(){
    $("#main1").hide();
    $("#main0").show();
    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('main0'));
    option1 && myChart.setOption(option1)
}
function yb(){
    $("#main0").hide();
    $("#main1").show();
    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('main1'));
    option2 && myChart.setOption(option2)
}
function zz(){
    $("#main1").hide();
    $("#main0").show();
    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('main0'));
    option && myChart.setOption(option)
}